<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <el-form ref="form" :model="form" label-width="80px" size="small">
      <el-form-item label="订单编号">
        <el-input v-model="form.orderNo" placeholder="请输入订单编号" size="small" style="width:200px"></el-input>
        <el-button type="primary" @click="handleSearch">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 按钮 -->
    <!-- <el-row style="margin-bottom:10px;">
      <el-button type="primary" size="mini" @click="handleAddUser">新增</el-button>
      <el-button type="danger" size="mini" @click="handleDeleteUser">删除</el-button>
    </el-row> -->

    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="订单编号">
        <template slot-scope="scope">{{ scope.row.orderNo }}</template>
      </el-table-column>
      <el-table-column label="订单金额">
        <template slot-scope="scope">{{ scope.row.totalMoney }}</template>
      </el-table-column>
      <el-table-column label="订单状态">
        <template slot-scope="scope">{{ scope.row.orderStatus }}</template>
      </el-table-column>
      <el-table-column label="支付状态">
        <template slot-scope="scope">{{ scope.row.payStatus }}</template>
      </el-table-column>
      <el-table-column label="备注">
        <template slot-scope="scope">{{ scope.row.descr }}</template>
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">{{ scope.row.createTime }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看</el-button> -->
          <el-button size="mini" @click="view(scope.row)">查看</el-button>
          <el-button size="mini" @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="pageSizes"
      :current-page="currentPage"
      :page-size="pageSize"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { getList } from "@/api/order";

export default {
  name: "Order",
//   components: { UserAdd, UserEdit, UserView },
  data() {
    return {
      list: null,
      listLoading: true,
      form: {
        orderNo: "",
      },
      pageSizes: [10, 20, 30, 40],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      mutipleSelection: [],
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      var params = {
        orderNo: this.form.orderNo,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };

      getList(params).then((response) => {
        if (response.data) {
          this.list = response.data.orders;
          this.total = response.data.total;
        } else {
          this.list = [];
          this.total = 0;
        }
        this.listLoading = false;
      });
    },
    // handleEditRole(index, row) {
    //   console.log(index, row);
    // },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.fetchData();
    },
    handleSearch() {
      this.fetchData();
    },
    handleSelectionChange(val) {
      console.log(val);
      this.mutipleSelection = val;
    },
  },
};
</script>
